package com.javasm.service.goods.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.javasm.common.page.PageResult;
import com.javasm.domin.criteria.goods.GoodsAdjustCriteria;
import com.javasm.domin.entity.goods.GoodsAdjust;
import com.javasm.domin.entity.goods.GoodsAdjustInfo;
import com.javasm.domin.vo.goods.GoodsAdjustVo;
import com.javasm.mapper.goods.GoodsAdjustMapper;
import com.javasm.service.base.impl.BaseServiceimpl;
import com.javasm.service.goods.IGoodsAdjustInfoService;
import com.javasm.transfer.goods.GoodsAdjustTransfer;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author whl
 * @since 2022-01-16
 */
@Service
@Transactional
@RequiredArgsConstructor
public class GoodsAdjustInfoServiceImpl extends BaseServiceimpl<GoodsAdjustInfo> implements IGoodsAdjustInfoService {

    private final GoodsAdjustMapper goodsAdjustMapper;
    private final GoodsAdjustTransfer goodsAdjustTransfer;

    /**
     * 分页条件查询
     */
    @Override
    public PageResult<GoodsAdjustVo> searchPage(GoodsAdjustCriteria goodsAdjustCriteria) {
        PageHelper.startPage(goodsAdjustCriteria.getCurrentPage(), goodsAdjustCriteria.getPageSize());
        LambdaQueryWrapper<GoodsAdjust> lambda = new QueryWrapper<GoodsAdjust>().lambda();

        if (!StringUtils.isEmpty(goodsAdjustCriteria.getGoodsName())) {
            lambda.like(GoodsAdjust::getGoodsName, goodsAdjustCriteria.getGoodsName());
        }
        if (!StringUtils.isEmpty(goodsAdjustCriteria.getEffectTime())) {
            lambda.like(GoodsAdjust::getEffectTime, goodsAdjustCriteria.getEffectTime());
        }
        if (!StringUtils.isEmpty(goodsAdjustCriteria.getExpireTime())) {
            lambda.like(GoodsAdjust::getExpireTime, goodsAdjustCriteria.getExpireTime());
        }

        List<GoodsAdjust> goodsAdjusts = goodsAdjustMapper.selectList(lambda);
        PageInfo<GoodsAdjust> pageInfo = new PageInfo<>(goodsAdjusts);
        List<GoodsAdjustVo> goodsAdjustVos = goodsAdjustTransfer.setInfo(goodsAdjusts);
        return new PageResult<GoodsAdjustVo>(pageInfo.getTotal(), goodsAdjustVos);
    }
}
